/*************************************************
** 功能 : 输出2个，3个，4个整数的最大公约数
** 作者 : 杨兰
 ** 版本 : 2021-10-23 / 17:11
 /**************************************************/

#include <iostream>
#include <cstdlib>
#include <windows.h>

using namespace std;

/*----------------------------------*
	   Class Definition
*-----------------------------------*/
//求两个数中的最小值
int minimun(int x1, int x2)
{
	int camp;
	camp = x1 <= x2 ? x1 : x2;
	return camp;
}
//求两个数中的最大公约数
int commenDivisor(int x1, int x2)
{
	int y, min;
	min = minimun(x1, x2);
	for (int i = 1;i <= min;i++)
	{
		if (x1 % i == 0 && x2 % i == 0)
			y = i;
	}
	return y;
}
//求三个数中的最大公约数
int commenDivisor(int x1, int x2, int x3)
{
	int y, min;
	min = minimun(minimun(x1, x2), x3);
	for (int i = 1;i <= min;i++)
	{
		if (x1 % i == 0 && x2 % i == 0 && x3%i == 0)
			y = i;
	}
	return y;
}
//求四个数中的最大公约数
int commenDivisor(int x1, int x2, int x3, int x4)
{
	int y, min;
	min = minimun(minimun(minimun(x1, x2), x3), x4);
	for (int i = 1;i <= min;i++)
	{
		if ((x1 % i == 0 && x2 % i == 0) && (x3 % i == 0 && x4 % i
			== 0))
			y = i;
	}
	return y;
}
/*----------------------------------*
	   Main Function
*-----------------------------------*/

int main()
{
	int m;
	int n;
	int x1, x2, x3, x4;
	cout << "enter a value to mean the numbers that you'll found 
		the commenDivisors among which : ";
		cin >> n;
	switch (n)
	{
	case 2:
		cout << "enter 2 numbers:";
		cin >> x1 >> x2;
		m = commenDivisor(x1, x2);
		cout << "The commenDivisor among " << x1 << "  " << x2 << " is : " << m << endl;
		break;
	case 3:
		cout << "enter 3 numbers:";
		cin >> x1 >> x2 >> x3;
		m = commenDivisor(x1, x2, x3);
		cout << "The commenDivisor among " << x1 << "  " << x2 << "  " <<
			x3 << " is :" << m << endl;
		break;
	case 4:
		cout << "enter 4 numbers:";
		cin >> x1 >> x2 >> x3 >> x4;
		m = commenDivisor(x1, x2, x3, x4);
		cout << "The commenDivisor among " << x1 << "  " << x2 << "  " <<
			x3 << "  " << x4 << " is :" << m << endl;
		break;
	default:
		cout << "error , The value of n is wrong! " << endl;
	}

	system("pause");
	return 0;
}